package com.gzhryc.pay.adaptation.alipay.msg.normal;

import com.alipay.api.AlipayApiException;
import com.alipay.api.internal.util.AlipaySignature;
import com.gzhryc.common.NumberTools;
import com.gzhryc.common.StringTools;
import com.gzhryc.common.json.JsonTools;

import java.io.Serializable;
import java.util.Map;

public class AlipayNormalPayNotify implements Serializable {

    private static final long serialVersionUID = 1L;
    
    final Map<String, String> params;
    final String payKey;
    final String appId;

    public AlipayNormalPayNotify(Map<String, String> params, String payKey,String appId) {
        this.params = params;
        this.payKey = payKey;
        this.appId = appId;
    }

    public String getTradeNo() {
        return this.params.get("out_trade_no");
    }

    public String getExternalTradeNo() {
        return this.params.get("trade_no");
    }

    public String getPayerId() {
        return this.params.get("buyer_id");
    }

    public String getSellerId(){
        return this.params.get("seller_id");
    }

    public Integer getMoney() {
        String receipt_amount = this.params.get("receipt_amount");
        if (StringTools.isNotBlank(receipt_amount)) {
            int money = NumberTools.changeMoney(Double.valueOf(receipt_amount));
            return money;
        } else {
            return null;
        }
    }

    public String getTradeStatus() {
        return this.params.get("trade_status");
    }

    public boolean isTrue() {
        if (StringTools.isNotBlank(this.payKey)) {
            try {
                return AlipaySignature.rsaCheckV1(this.params, this.payKey, "UTF-8", "RSA2");
            } catch (AlipayApiException var2) {
                var2.printStackTrace();
            }
        }

        return false;
    }

    public Map<String, String> getParams() {
        return params;
    }

    public String getJson() {
        return JsonTools.toJson(this.params);
    }

	public String getAppId() {
		return appId;
	}

}
